<?php

if (isset($_COOKIE['id']) and isset($_COOKIE['hash'])) {
	require_once ($_SERVER["DOCUMENT_ROOT"] ."/include/config.php");

	mysql_connect($db_host, $db_user, $db_pass);

	mysql_select_db($db_name);
	
	$query = mysql_query("SELECT *, INET_NTOA(user_ip) as user_ip FROM users WHERE user_id = '" . $_COOKIE['id'] . "' LIMIT 1");

	$userdata = mysql_fetch_assoc($query);

	if (($userdata['user_hash'] !== $_COOKIE['hash']) or ($userdata['user_id'] !== $_COOKIE['id']) or (($userdata['user_ip'] !== $_SERVER['REMOTE_ADDR']) and ($userdata['user_ip'] !== "0.0.0.0"))) {

		setcookie("id", "", time() - 3600 * 24 * 30 * 12, "/");
		setcookie("hash", "", time() - 3600 * 24 * 30 * 12, "/");
		echo '<meta http-equiv="refresh" content="0;URL=/login.php">';
	    exit();
	}
	$location = $userdata['location'];
	$zoom = $userdata['zoom'];
	$layer = $userdata['layer'];
	$username = $userdata['user_login'];
	$user_id = $userdata['user_id'];
	$isAdmin = $userdata["admin"]; 
	
} else {
	echo '<meta http-equiv="refresh" content="0;URL=/login.php">';
	exit();
}


?>